<?php
class Users extends CI_Model{
	
	function getActive($id){
		$sql  ="SELECT * FROM users u ";
		$sql .="WHERE username='".$id."'";
		$Q = $this->db->query($sql);
        if ($Q->num_rows() > 0):
            $data=$Q->row_array();
        endif;
		$Q->free_result();
        return $data;
	}
	
	function getUpdate($id){
		$value = array  (
                            'name' 			=>  $this->input->post('name'),
                            'address' 		=>  $this->input->post('address'),
                            'tlp'           =>  $this->input->post('tlp'),
                            'email'         =>  $this->input->post('email'),
                            'city'          =>  $this->input->post('city'),
                            'zip_code'      =>  $this->input->post('zip'),
                            'hobby'         =>  $this->input->post('hobby'),
                            'user_stamp'    =>  $this->session->userdata('user_id'),
                            'date_stamp'    =>  date('Y-m-d')
                        );
		$this->db->where('username',$id);				
        $this->db->update('users',$value);
    }
	
	function checkUser($user,$password){
		$sql  =" SELECT * FROM users u ";
		$sql .=" WHERE username='".$user."'";
		$sql .=" AND password='".$password."'";
		$Q = $this->db->query($sql);
        return $Q->num_rows();
	}
	
	function getUpdatePassword($id){
		$value = array  (
                            'password' 		=>  sha1($this->input->post('password'))
                
                        );
		$this->db->where('username',$id);				
        $this->db->update('users',$value);
    }
    
        
}